from django.db import models


# 管理员信息
class UserInfo(models.Model):
    username = models.CharField(verbose_name="账号", max_length=50, primary_key=True)
    password = models.CharField(verbose_name="密码", max_length=50)
    is_superuser = models.BooleanField(default=False, verbose_name="超级管理员")


# 年级信息
class GradeInfo(models.Model):
    grade_choices = [
        ("1", "大一"),
        ("2", "大二"),
        ("3", "大三"),
        ("4", "大四")
    ]
    grade_id = models.CharField(verbose_name="年级ID", max_length=50, primary_key=True, choices=grade_choices)
    grade_year = models.CharField(verbose_name="年级届次", max_length=50, unique=True)

    def __str__(self):
        return f"{self.grade_id}（{self.grade_year}）"


class ClassInfo(models.Model):
    class_id = models.IntegerField(verbose_name="班级ID", primary_key=True)
    class_name = models.CharField(verbose_name="班级名称", max_length=50)
    grade_id = models.ForeignKey(GradeInfo, verbose_name="年级ID", on_delete=models.CASCADE)

    def __str__(self):
        return f"{self.class_id}（{self.class_name}）"


class StudentInfo(models.Model):

    def __str__(self):
        return self.get_student_gender_display(), self.get_student_profession_display(), self.get_student_class_display()

    student_id = models.CharField(
        verbose_name="学号",
        max_length=20,
        primary_key=True
    )
    student_name = models.CharField(verbose_name="学生姓名", max_length=50)

    gender_choices = [
        ("1", "男"),
        ("2", "女"),
    ]
    student_gender = models.CharField(verbose_name="性别", max_length=50, choices=gender_choices)

    profession_choices = [
        ("1", "软件工程"),
        ("2", "物联网工程"),
        ("3", "计算机科学与技术"),
        ("4", "人工智能"),
    ]
    student_profession = models.CharField(verbose_name="专业", max_length=50, choices=profession_choices)
    student_birthday = models.DateField(verbose_name="出生日期")
    student_phone = models.CharField(verbose_name="联系电话", max_length=50)

    student_class = models.ForeignKey(
        ClassInfo,
        verbose_name="所属班级",
        on_delete=models.CASCADE
    )


# 新建数据
# UserInfo.objects.create(username="admin", password="123456")

"""
上面的语句直接在数据库中执行为：
create table StuApp_UserInfo(
    id bigint primary key auto_increment,
    username varchar(50) not null,
    password varchar(50) not null,
    email varchar(100) not null,
    phone varchar(15) not null,
    address varchar(200) not null,
)
"""

# class Department(models.Model):
#     name = models.CharField(max_length=50)
#     location = models.CharField(max_length=100)
#     head = models.CharField(max_length=50)
